# -*- coding: utf-8 -*-
from functools import partial

from w.blocks.containers.block import Block

from w.html.doctypes.preferable import Input

class BaseButton(Block):
    def __init__(self, content=None, fixedSize=None, *argv, **kwargv):
        if isinstance(content, list):
            raise ValueError("Content can't be a list")

        Block.__init__(self, content)

        self.fixedSize = fixedSize
        self.tag = Input(*argv, **kwargv)
        self.html = self.tag.html

    def make(self, content=[]):
        if not content:
            content = self
        if content:
            content = content[0]
            self.tag.html.value = content
            self.tag.html.size = self.fixedSize if self.fixedSize else len(unicode(content, 'utf-8'))+1+2
        return Block.make(self, [self.tag,])

Button = partial(BaseButton, htype='button')
OKButton = partial(BaseButton, htype='submit')
ClearButton = partial(BaseButton, htype='reset')
